home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / cvs-1_3.lha / cvs-1.3 / contrib / sccs2rcs < prev   
Text File  |  1992-04-09  |  8KB  |  278 lines

  1. #!/bin/csh -f
  2. #
  3. # Sccs2rcs is a script to convert an existing SCCS
  4. # history into an RCS history without losing any of
  5. # the information contained therein.
  6. # It has been tested under the following OS's:
  7. #     SunOS 3.5, 4.0.3, 4.1
  8. #     Ultrix-32 2.0, 3.1
  9. #
  10. # Things to note:
  11. #   + It will NOT delete or alter your ./SCCS history under any circumstances.
  12. #
  13. #   + Run in a directory where ./SCCS exists and where you can
  14. #       create ./RCS
  15. #
  16. #   + /usr/local/bin is put in front of the default path.
  17. #     (SCCS under Ultrix is set-uid sccs, bad bad bad, so
  18. #     /usr/local/bin/sccs here fixes that)
  19. #
  20. #   + Date, time, author, comments, branches, are all preserved.
  21. #
  22. #   + If a command fails somewhere in the middle, it bombs with
  23. #     a message -- remove what it's done so far and try again.
  24. #         "rm -rf RCS; sccs unedit `sccs tell`; sccs clean"
  25. #     There is no recovery and exit is far from graceful.
  26. #     If a particular module is hanging you up, consider
  27. #     doing it separately; move it from the current area so that
  28. #     the next run will have a better chance or working.
  29. #     Also (for the brave only) you might consider hacking
  30. #     the s-file for simpler problems:  I've successfully changed
  31. #     the date of a delta to be in sync, then run "sccs admin -z"
  32. #     on the thing.
  33. #
  34. #   + After everything finishes, ./SCCS will be moved to ./old-SCCS.
  35. #
  36. # This file may be copied, processed, hacked, mutilated, and
  37. # even destroyed as long as you don't tell anyone you wrote it.
  38. #
  39. # Ken Cox
  40. # Viewlogic Systems, Inc.
  41. # kenstir@viewlogic.com
  42. # ...!harvard!cg-atla!viewlog!kenstir
  43. #
  44. # Various hacks made by Brian Berliner before inclusion in CVS contrib area.
  45. #
  46. # sccs2rcs,v 1.1 1992/04/10 03:04:26 berliner Exp
  47.  
  48.  
  49. #we'll assume the user set up the path correctly
  50. # for the Pmax, /usr/ucb/sccs is suid sccs, what a pain
  51. #   /usr/local/bin/sccs should override /usr/ucb/sccs there
  52. set path = (/usr/local/bin $path)
  53.  
  54.  
  55. ############################################################
  56. # Error checking
  57. #
  58. if (! -w .) then
  59.     echo "Error: ./ not writeable by you."
  60.     exit 1
  61. endif
  62. if (! -d SCCS) then
  63.     echo "Error: ./SCCS directory not found."
  64.     exit 1
  65. endif
  66. set edits = (`sccs tell`)
  67. if ($#edits) then
  68.     echo "Error: $#edits file(s) out for edit...clean up before converting."
  69.     exit 1
  70. endif
  71. if (-d RCS) then
  72.     echo "Warning: RCS directory exists"
  73.     if (`ls -a RCS | wc -l` > 2) then
  74.         echo "Error: RCS directory not empty
  75.         exit 1
  76.     endif
  77. else
  78.     mkdir RCS
  79. endif
  80.  
  81. sccs clean
  82.  
  83. set logfile = /tmp/sccs2rcs_$$_log
  84. rm -f $logfile
  85. set tmpfile = /tmp/sccs2rcs_$$_tmp
  86. rm -f $tmpfile
  87. set emptyfile = /tmp/sccs2rcs_$$_empty
  88. echo -n "" > $emptyfile
  89. set initialfile = /tmp/sccs2rcs_$$_init
  90. echo "Initial revision" > $initialfile
  91. set sedfile = /tmp/sccs2rcs_$$_sed
  92. rm -f $sedfile
  93. set revfile = /tmp/sccs2rcs_$$_rev
  94. rm -f $revfile
  95.  
  96. # the quotes surround the dollar signs to fool RCS when I check in this script
  97. set sccs_keywords = (\
  98.     '%W%[     ]*%G%'\
  99.     '%W%[     ]*%E%'\
  100.     '%W%'\
  101.     '%Z%%M%[     ]*%I%[     ]*%G%'\
  102.     '%Z%%M%[     ]*%I%[     ]*%E%'\
  103.     '%M%[     ]*%I%[     ]*%G%'\
  104.     '%M%[     ]*%I%[     ]*%E%'\
  105.     '%M%'\
  106.     '%I%'\
  107.     '%G%'\
  108.     '%E%'\
  109.     '%U%')
  110. set rcs_keywords = (\
  111.     '$'Id'$'\
  112.     '$'Id'$'\
  113.     '$'Id'$'\
  114.     '$'SunId'$'\
  115.     '$'SunId'$'\
  116.     '$'Id'$'\
  117.     '$'Id'$'\
  118.     '$'RCSfile'$'\
  119.     '$'Revision'$'\
  120.     '$'Date'$'\
  121.     '$'Date'$'\
  122.     '')
  123.  
  124.  
  125. ############################################################
  126. # Get some answers from user
  127. #
  128. echo ""
  129. echo "Do you want to be prompted for a description of each"
  130. echo "file as it is checked in to RCS initially?"
  131. echo -n "(y=prompt for description, n=null description) [y] ?"
  132. set ans = $<
  133. if ((_$ans == _) || (_$ans == _y) || (_$ans == _Y)) then
  134.     set nodesc = 0
  135. else
  136.     set nodesc = 1
  137. endif
  138. echo ""
  139. echo "The default keyword substitutions are as follows and are"
  140. echo "applied in the order specified:"
  141. set i = 1
  142. while ($i <= $#sccs_keywords)
  143. #    echo '    '\"$sccs_keywords[$i]\"'    ==>    '\"$rcs_keywords[$i]\"
  144.     echo "    $sccs_keywords[$i]    ==>    $rcs_keywords[$i]"
  145.     @ i = $i + 1
  146. end
  147. echo ""
  148. echo -n "Do you want to change them [n] ?"
  149. set ans = $<
  150. if ((_$ans != _) && (_$ans != _n) && (_$ans != _N)) then
  151.     echo "You can't always get what you want."
  152.     echo "Edit this script file and change the variables:"
  153.     echo '    $sccs_keywords'
  154.     echo '    $rcs_keywords'
  155. else
  156.     echo "good idea."
  157. endif
  158.  
  159. # create the sed script
  160. set i = 1
  161. while ($i <= $#sccs_keywords)
  162.     echo "s,$sccs_keywords[$i],$rcs_keywords[$i],g" >> $sedfile
  163.     @ i = $i + 1
  164. end
  165.  
  166. onintr ERROR
  167.  
  168. ############################################################
  169. # Loop over every s-file in SCCS dir
  170. #
  171. foreach sfile (SCCS/s.*)
  172.     # get rid of the "s." at the beginning of the name
  173.     set file = `echo $sfile:t | sed -e "s/^..//"`
  174.  
  175.     # work on each rev of that file in ascending order
  176.     set firsttime = 1
  177.     sccs prs $file | grep "^D " | awk '{print $2}' | sed -e 's/\./ /g' | sort -n -u +0 +1 +2 +3 +4 +5 +6 +7 +8 | sed -e 's/ /./g' > $revfile
  178.     foreach rev (`cat $revfile`)
  179.         if ($status != 0) goto ERROR
  180.  
  181.         # get file into current dir and get stats
  182.         set date = `sccs prs -r$rev $file | grep "^D " | awk '{printf("19%s %s", $3, $4); exit}'`
  183.         set author = `sccs prs -r$rev $file | grep "^D " | awk '{print $5; exit}'`
  184.         echo ""
  185.         echo "==> file $file, rev=$rev, date=$date, author=$author"
  186.         sccs edit -r$rev $file >>& $logfile
  187.         if ($status != 0) goto ERROR
  188.         echo checked out of SCCS
  189.  
  190.         # add RCS keywords in place of SCCS keywords
  191.         sed -f $sedfile $file > $tmpfile
  192.         if ($status != 0) goto ERROR
  193.         echo performed keyword substitutions
  194.         cp $tmpfile $file
  195.  
  196.         # check file into RCS
  197.         if ($firsttime) then
  198.             set firsttime = 0
  199.             if ($nodesc) then
  200.         echo about to do ci
  201.                 echo ci -f -r$rev -d"$date" -w$author -t$emptyfile $file 
  202.                 ci -f -r$rev -d"$date" -w$author -t$emptyfile $file < $initialfile >>& $logfile
  203.                 if ($status != 0) goto ERROR
  204.                 echo initial rev checked into RCS without description
  205.             else
  206.                 echo ""
  207.                 echo Enter a brief description of the file $file \(end w/ Ctrl-D\):
  208.                 cat > $tmpfile
  209.                 ci -f -r$rev -d"$date" -w$author -t$tmpfile $file < $initialfile >>& $logfile
  210.                 if ($status != 0) goto ERROR
  211.                 echo initial rev checked into RCS
  212.             endif
  213.         else
  214.             # get RCS lock
  215.         set lckrev = `echo $rev | sed -e 's/\.[0-9]*$//'`
  216.         if ("$lckrev" =~ [0-9]*.*) then
  217.         # need to lock the brach -- it is OK if the lock fails
  218.         rcs -l$lckrev $file >>& $logfile
  219.         else
  220.         # need to lock the trunk -- must succeed
  221.                 rcs -l $file >>& $logfile
  222.                 if ($status != 0) goto ERROR
  223.         endif
  224.             echo got lock
  225.             sccs prs -r$rev $file | grep "." > $tmpfile
  226.             # it's OK if grep fails here and gives status == 1
  227.             # put the delta message in $tmpfile
  228.             ed $tmpfile >>& $logfile <<EOF
  229. /COMMENTS
  230. 1,.d
  231. w
  232. q
  233. EOF
  234.             ci -f -r$rev -d"$date" -w$author $file < $tmpfile >>& $logfile
  235.             if ($status != 0) goto ERROR
  236.             echo checked into RCS
  237.         endif
  238.         sccs unedit $file >>& $logfile
  239.         if ($status != 0) goto ERROR
  240.     end
  241.     rm -f $file
  242. end
  243.  
  244.  
  245. ############################################################
  246. # Clean up
  247. #
  248. echo cleaning up...
  249. mv SCCS old-SCCS
  250. rm -f $tmpfile $emptyfile $initialfile $sedfile
  251. echo ===================================================
  252. echo "       Conversion Completed Successfully"
  253. echo ""
  254. echo "         SCCS history now in old-SCCS/"
  255. echo ===================================================
  256. set exitval = 0
  257. goto cleanup
  258.  
  259. ERROR:
  260. foreach f (`sccs tell`)
  261.     sccs unedit $f
  262. end
  263. echo ""
  264. echo ""
  265. echo Danger\!  Danger\!
  266. echo Some command exited with a non-zero exit status.
  267. echo Log file exists in $logfile.
  268. echo ""
  269. echo Incomplete history in ./RCS -- remove it
  270. echo Original unchanged history in ./SCCS
  271. set exitval = 1
  272.  
  273. cleanup:
  274. # leave log file
  275. rm -f $tmpfile $emptyfile $initialfile $sedfile $revfile
  276.  
  277. exit $exitval
  278.